package org.demis.dwarf.core.mapping.util;


import java.util.StringTokenizer;

public class NameConverter {
    public static String convertDataBaseName(String name) {
        return convertDataBaseName(name, true);
    }

    public static String convertDataBaseName(String name, boolean removeIdinName) {
        String baseName = name.toLowerCase();
        StringTokenizer tokenizer = new StringTokenizer(baseName, "_");
        StringBuffer buffer = new StringBuffer("");
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            if (!(token.equalsIgnoreCase("id") && removeIdinName && !tokenizer.hasMoreTokens())) {
                buffer.append(token.substring(0, 1).toUpperCase());
                buffer.append(token.substring(1, token.length()).toLowerCase());
            }
        }
        return buffer.toString();
    }

    public static String toUpperCaseFirst(String value) {
        if (value == null || value.length() == 0) {
            return value;
        }
        return value.substring(0, 1).toUpperCase() +  value.substring(1, value.length());
    }

    public static String toLowerCaseFirst(String value) {
        if (value == null || value.length() == 0) {
            return value;
        }
        return value.substring(0, 1).toLowerCase() +  value.substring(1, value.length());
    }
}
